#include <ros/ros.h>
#include "turtlesim/Pose.h"

// 接收到订阅的消息后，会进入消息回调函数
void poseCallback(const turtlesim::Pose::ConstPtr& msg)
{
    // 将接收到的消息打印出来
	float x, y, theta,linear_velocity,angular_velocity;
	x=msg->x;
	y=msg->y;
	theta=msg->theta;
	linear_velocity=msg->linear_velocity;
	angular_velocity=msg->angular_velocity;
    ROS_INFO("x:[%f] y:[%f] z:[%f] linear_velocity:[%f] angular_velocity[%f]",x, y, theta,linear_velocity,angular_velocity);
}

int main(int argc, char **argv)
{
	if (argc != 2)
	{
		ROS_INFO("rosrun cmd turtle_pos /<name>/pose");		
		return -1;
	}
    // 初始化ROS节点
    ros::init(argc, argv, "pose_subscriber");

    // 创建节点句柄
    ros::NodeHandle n;

    // 创建一个Subscriber，订阅名为/argv[1]的topic，注册回调函数PoseCallback
    ros::Subscriber person_info_sub = n.subscribe(argv[1],10, poseCallback);

    // 循环等待回调函数
    ros::spin();

    return 0;
}
